<template>
    <div>
        <el-form ref="CustomerForm" :inline="true" :model="CustomerForm" class="tpl-form-inline pb0">
            <el-form-item label="车架号">
                <el-select v-model="CustomerForm.CarNo" placeholder="全部">
                    <el-option label="预警车辆" value="预警车辆">预警车辆</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="汽车品牌">
                <el-select v-model="CustomerForm.brand" placeholder="全部">
                    <el-option label="丰田" value="丰田">丰田</el-option>
                    <el-option label="长城" value="长城">长城</el-option>
                    <el-option label="大众" value="大众">大众</el-option>
                    <el-option label="长安" value="长安">长安</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="服务状态">
                <el-select v-model="CustomerForm.serviceStatus" placeholder="全部">
                    <el-option label="已开通" value="已开通">已开通</el-option>
                    <el-option label="确认中" value="确认中">确认中</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="保险状态">
                <el-select v-model="CustomerForm.bxType" placeholder="全部">
                    <el-option label="保障中" value="保障中">保障中</el-option>
                    <el-option label="待起保" value="待起保">待起保</el-option>
                    <el-option label="已脱保" value="已脱保">已脱保</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="销售渠道">
                <el-select v-model="CustomerForm.salesType" placeholder="全部">
                    <el-option label="4S店" value="4S店">4S店</el-option>
                    <el-option label="经销商" value="经销商">经销商</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="所在地区">
                <el-select v-model="CustomerForm.region" placeholder="全部">
                    <el-option label="省/市/区" value="省/市/区">省/市/区</el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div class="mt10 mb20">
            <el-button type="primary" icon="el-icon-search" @click="queryList" :disabled="loading">查询</el-button>
            <el-button @click="reset" icon="el-icon-refresh" :disabled="loading">重置</el-button>
            <el-button type="primary" icon="el-icon-download" @click="exportFile" >导出</el-button>
        </div>
        <div class="text item">
            <el-table class="sd" stripe border :data="tableData" v-loading="loading">
                <el-table-column align="center" prop="index" label="序号" width="100"></el-table-column>
                <el-table-column align="center" prop="brand" label="汽车品牌"></el-table-column>
                <el-table-column align="center" prop="vCode" label="车辆VIN码"></el-table-column>
                <el-table-column align="center" prop="bxType" label="保险状态"></el-table-column>
                <el-table-column align="center" prop="isOpen" label="是否续保"></el-table-column>
                <el-table-column align="center" prop="salesType" label="销售渠道"></el-table-column>
                <el-table-column align="center" prop="serviceStatus" label="服务状态"></el-table-column>
                <el-table-column align="center" prop="region" label="所在地区"></el-table-column>
                <el-table-column align="center" prop="bonus" label="累计奖励金"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text"
                            @click="handleEdit(scope.$index, scope.row)">查看详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination class="tpl-mg-t mt20 fr"
                            small
                            @size-change="pageSizeChange"
                            @current-change="pageCurrentChange"
                            :current-page="CustomerForm.pageNum"
                            :page-sizes="[10, 20, 30, 40, 50, 100]"
                            :page-size="CustomerForm.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total">
            </el-pagination>
        </div>

    </div>
</template>

<script>
    export default {
        name: 'depotInfo',
        data () {
            // 表单校验手机号 （0-11位数字）
            let phoneValidator = (rule, value, callback) => {
                if (!value || value === '' || value.match(/^\d{0,11}$/)) {
                    callback()
                } else {
                    callback(new Error('只能输入数字'))
                }
            }
            return {
                // 查询表单
                CustomerForm: {
                    CarNo: '',
                    brand: '',
                    serviceStatus: '',
                    bxType: '',
                    salesType: '',
                    region: ''
                },
                // 数据总条数
                total: 0,
                // 表格数据
                tableData: [],
                newData: [],
                // 选中数据
                tableSelection: [],
                params: {},
                loading: false
            }
        },
        mounted () {
            this.getList()
        },
        computed: {
        },
        methods: {
            handleEdit (i,r) {
                this.$routerTo('depotDetail', { depotData: r, callback: this.getList });
            },
            // 点击查询置为第一页
            queryList () {
                this.params = { ...this.CustomerForm }
                for (let key in this.params) {
                    if (!this.params[key] || this.params[key] === '' || this.params[key].length === 0) {
                        delete this.params[key]
                    }
                }
                this.tableData = this.$filters(this.params, this.newData);
            },
            // 获取列表
            getList () {
                let cData = JSON.parse(localStorage.getItem('depotData'));
                if(!cData){
                    cData = [
                        {"index": "1","brand": "丰田","vCode": "LESHS872HANSKDY83","bxType": "已脱保","isOpen": "是","salesType": "4S店","serviceStatus": "已开通","region": "北京市房山区","bonus": "5,000元"},
                        {"index": "2","brand": "丰田","vCode": "LESHS872HANSKDY83","bxType": "待起保","isOpen": "是","salesType": "经销商","serviceStatus": "确认中","region": "北京市房山区","bonus": "5,000元"},
                        {"index": "3","brand": "大众","vCode": "LESHS872HANSKDY83","bxType": "保障中","isOpen": "是","salesType": "4S店","serviceStatus": "已开通","region": "北京市房山区","bonus": "5,000元"},
                        {"index": "4","brand": "长安","vCode": "LESHS872HANSKDY83","bxType": "保障中","isOpen": "是","salesType": "4S店","serviceStatus": "已开通","region": "北京市房山区","bonus": "5,000元"}
                    ]
                }
                localStorage.setItem('depotData', JSON.stringify(cData));
                this.tableData = cData;
                this.newData = cData;
                this.total = this.tableData.length;
            },
            // 重置表单
            reset () {
                this.CustomerForm = {
                    CarNo: '',
                    brand: '',
                    serviceStatus: '',
                    bxType: '',
                    salesType: '',
                    region: ''
                }
                this.$nextTick(() => {
                    this.getList()
                })
            },
            exportFile () {
                if(this.CustomerForm.birthday[0] || this.CustomerForm.vCode != "" || this.CustomerForm.bsType !== "" || this.CustomerForm.bxType !== "" || this.CustomerForm.zjType !== ""){
                    this.$message({ type: 'success', message: `导出成功!` })
                }else{
                    this.$message.warning('请先选择筛选条件！')
                }
                // let params = { ...this.form }
                // for (let key in params) {
                //     if (params[key] === '' || params[key].length === 0) {
                //         delete params[key]
                //     }
                // }
                // if (this.form.dateRange && this.form.dateRange.length === 2) {
                //     params.tssTimeStart = this.form.dateRange[0]
                //     params.tssTimeEnd = this.form.dateRange[1]
                // } else {
                //     this.$message.warning('请选择发生日期范围')
                //     return
                // }
                // /* 请求部分 */
                // let config = {
                //     headers: {}
                // }
                // let token = window.localStorage.getItem('token') || null
                // let account = window.localStorage.getItem('account') || null
                // if (token) {
                //     config.headers['Token'] = token
                //     config.headers['account'] = account
                //     config.responseType = 'blob'
                // }
                // axios.post(`${baseURL}icall/exportIcall`, params, config).then(res => {
                //     let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
                //     let downloadElement = document.createElement('a')
                //     let href = URL.createObjectURL(blob)
                //     downloadElement.href = href
                //     downloadElement.download = 'chart.xls'
                //     document.body.appendChild(downloadElement)
                //     downloadElement.click()
                //     document.body.removeChild(downloadElement)
                //     window.URL.revokeObjectURL(href)
                // }).catch(e => {
                //     let reader = new FileReader()
                //     reader.onload = event => {
                //         let content = reader.result
                //         let json = JSON.parse(content)
                //         if (json) {
                //             this.$message.error(json.message)
                //         } else {
                //             this.$message.error('导出失败')
                //         }
                //     }
                //     reader.readAsText(e.response.data)
                // })
            },
            // 每页显示条数
            pageSizeChange (val) {
                let pages = Math.ceil(this.total / val)
                this.CustomerForm.pageSize = val
                this.params.pageSize = val
                if (this.CustomerForm.pageNum > pages) {
                    this.CustomerForm.pageNum = 1
                    this.params.pageNum = 1
                }
                this.queryList()
            },
            // 当前页码
            pageCurrentChange (val) {
                this.CustomerForm.pageNum = val
                this.params.pageNum = val
                this.queryList()
            },
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped rel="stylesheet/scss">

</style>
